package com.yanqu.road.server.cmd.monopolymarket.office;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.monopolymarket.MonopolyMarketProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.monopolymarket.MonopolyMarketOfficeMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

/**
 * @Description
 * @Author cwq
 * @Data 2021/8/12 17:08
 */
@Cmd(code = Protocol.C_CROSS_MONOPOLY_MARKET_OFFICE_ACTION, desc = "进入大宋榷署 抢夺/撤回位置")
public class CrossMonopolyMarketOfficeActionCmd extends CrossCommand {

    private long userId;
    private int posIndex;
    private int seatTime;
    private long seatUserId;
    private int type;
    private byte decorationClass;
    private int decorationOverTime;
    private UserBaseInfo userBaseInfo;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MonopolyMarketProto.MonopolyMarketOfficeActionCrossReqMsg req = MonopolyMarketProto.MonopolyMarketOfficeActionCrossReqMsg.parseFrom(packet.getBytes());
        posIndex = req.getCtsMsg().getPosIndex();
        seatTime = req.getCtsMsg().getSeatTime();
        seatUserId = req.getCtsMsg().getSeatUserId();
        type = req.getCtsMsg().getType();
        userId = packet.getPlayerId();
        if(req.hasPlayerInfo()){
            decorationClass = (byte)(req.getDecorationClass());
            decorationOverTime = req.getDecorationOverTime();
            userBaseInfo = PlayerBasePb.parseToUserBaseInfo(req.getPlayerInfo());
        }
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        MessageHelper.sendPacket(serverId, userId , YanQuMessageUtils.buildMessage(GameProtocol.S_MONOPOLY_MARKET_OFFICE_ACTION_FROM_CROSS, MonopolyMarketOfficeMgr.action(type,posIndex,seatTime,seatUserId,userId,serverId,decorationClass,decorationOverTime,userBaseInfo)));
    }

    @Override
    public void sendData() {

    }
}
